package com.zzx.day57Demo.action;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.google.gson.Gson;
import com.opensymphony.xwork2.ActionSupport;
import com.zzx.day57Demo.model.AjaxMsgModel;



public class BaseAction extends ActionSupport{
	public void writeJsonString(String status,String message,String refreshTab, boolean isCloseCurrent){
		String closeCurrentString = isCloseCurrent ? "closeCurrent" : "";
	
	AjaxMsgModel m = new AjaxMsgModel(status, message, refreshTab, "", closeCurrentString, "");
	String jsonStr = new Gson().toJson(m);
	writeJsonString(jsonStr);
}
	
private void writeJsonString(String jsonStr){
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("application/json;charset=UTF8");
	try {
		response.getWriter().print(jsonStr);
	} catch (IOException e) {
		e.printStackTrace();
	}
  }
}




